package com.jstyle.jclife.utils;


//import com.itextpdf.kernel.color.Color;
//import com.itextpdf.kernel.color.DeviceRgb;
//import com.itextpdf.kernel.font.PdfFont;
//import com.itextpdf.kernel.font.PdfFontFactory;
//import com.itextpdf.kernel.geom.PageSize;
//import com.itextpdf.kernel.pdf.PdfDocument;
//import com.itextpdf.kernel.pdf.PdfPage;
//import com.itextpdf.kernel.pdf.PdfWriter;
//import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
//import com.itextpdf.layout.Document;


/**
 * Created by Administrator on 2019/4/2.
 */

public class PdfUtils {
//    final static int maxXSize=5120;
//    final static int length=20;
//    final static float totalWidth = 1010;
//
//    public static void createFile(String path,List<Double>data,String date) {
//        try {
//            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(path));
//            Document document=new Document(pdfDocument);
//
//
//            int size = data.size();
//            float col = size % maxXSize == 0 ? size / maxXSize : size / maxXSize + 1;//一次画5120个点，分多少次画
//            float height = length;
//            float width = length;
//            float totalHeight = col * height * 5+50;//一次需要5个高度
//            PageSize pageSize = new PageSize(totalWidth, totalHeight + 200);
//            PdfPage pdfPage = pdfDocument.addNewPage(pageSize);
//            PdfCanvas pdfCanvas = new PdfCanvas(pdfPage);
//            Color colorLine = new DeviceRgb(243, 119, 99);
//            Color colorS=new DeviceRgb(255, 0, 0);
////            Paragraph paragraphTips=new Paragraph().setTextAlignment(TextAlignment.RIGHT);
////            paragraphTips.setFont(font);
////            paragraphTips.add("地方反复是");
////            document.add(paragraphTips);
//            int startX = 0;
//            int startY = 50;
//            float endX = 1000;
//            float endY = totalHeight;
//            addParagraph(pdfCanvas,date,totalHeight+200);
//
//            pdfCanvas.setStrokeColor(colorLine).setLineWidth(0.1f);
//            for (int i = 0; i < 50; i++) {
//                pdfCanvas.moveTo(i * width, startY)
//                        .lineTo(i * width, endY);
//            }
//            for (int i = 0; i <= col * 5; i++) {
//                pdfCanvas.moveTo(startX, i * height+startY)
//                        .lineTo(endX, i * height+startY);
//            }
//            pdfCanvas.stroke();
//          //  pdfExtGState.setStrokeOpacity(1f);
//            pdfCanvas.setStrokeColor(colorS).setLineWidth(1f);
//            for (int i = 0; i < 11; i++) {
//                pdfCanvas.moveTo(i*5 * width, startY-20)
//                        .lineTo(i*5 * width, endY);
//                pdfCanvas.setTextMatrix(i*5 * width-10, startY-40);
//                pdfCanvas.showText(i+"s");
//            }
//            pdfCanvas.stroke();
//            pdfCanvas.setStrokeColor(new DeviceRgb(0,0,0));
//            out:
//            for (int i = 0; i < col; i++) {
//                int startPoint = i * maxXSize;
//                for (int j = 0; j < maxXSize; j++) {
//                    int x = j;
//                    if (startPoint + j >= size) break out;
//                    Double y = data.get(startPoint + j);
//                    if (j == 0) pdfCanvas.moveTo(0, (col - 1 - i) * height * 5 + getCanvasY(y));
//                    pdfCanvas.lineTo(x * endX / maxXSize, (col - 1 - i) * height * 5 + getCanvasY(y));
//                }
//            }
//
//            pdfCanvas.stroke();
//            document.close();
//            pdfDocument.close();
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
//    }
//
//    private static void addParagraph(PdfCanvas pdfCanvas,String date,float totalHeight){
//        UserInfo userInfo= UserInfoDaoManager.getUserByUid(NetWorkUtil.getUserId());
//        try {
//           // PdfFont f3 = PdfFontFactory.createFont("C:/Windows/Fonts/simhei.ttf", PdfEncodings.IDENTITY_H,true);
//            PdfFont font = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H", false);
//
//            pdfCanvas.setFontAndSize(font, 25);
//
//            String name=userInfo.getName();
//            int gender=userInfo.getGender();
//            String genderString=gender==0?"Male":"Female";
//            String birthday=userInfo.getBirthday();
//            String[]birthdayArray=birthday.split("-");
//            int year= Integer.parseInt(birthdayArray[0]);
//            Calendar calendar=Calendar.getInstance();
//            int nowYear=calendar.get(Calendar.YEAR);
//            int age = nowYear-year;
//            int userWeight=userInfo.getWeight();
//            int userHeight=userInfo.getHeight();
//            //标题
//            pdfCanvas.setTextMatrix(totalWidth/2-150, totalHeight - 70);
//            pdfCanvas.showText("ECG Report(Lead Ⅰ)");
//            //提醒
//
//            pdfCanvas.setTextMatrix(totalWidth -250, totalHeight - 50);
//            pdfCanvas.showText("The report is for reference only");
//            //个人信息
//            pdfCanvas.setTextMatrix(totalWidth/2-300, totalHeight - 110);
//            pdfCanvas.showText("Name: "+name+" "+" Gender: "+genderString+
//                    " Age: "+age+" Height: "+userHeight+"cm "+"Weight: "+userWeight+"kg");
//
//            //时间
//            pdfCanvas.setTextMatrix(totalWidth-250, totalHeight - 180);
//            pdfCanvas.showText("Date: "+date);
//         //   pdfCanvas.stroke();
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//
////        paragraphDate.add("Date: "+date);
////        document.add(paragraphDate);
//    }
    private static float getCanvasY(double value) {
        float height = 5 * 20 / 16000f;
        return (float) (height * (value + 8000)+50);
    }


}
